package com.example.passwordmanager;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;
import com.example.passwordmanager.PasswordRepository;
import java.util.List;

@Dao
public interface PasswordDao {
    @Insert
    void insert(PasswordRepository passwordEntry);

    @Update
    void update(PasswordRepository passwordEntry);

    @Delete
    void delete(PasswordRepository passwordEntry);

    @Query("SELECT * FROM password_entries ORDER BY lastModifiedDate DESC")
    LiveData<List<PasswordRepository>> getAllPasswords();

    @Query("SELECT * FROM password_entries WHERE id = :id")
    LiveData<PasswordRepository> getPasswordById(int id);

    @Query("SELECT * FROM password_entries WHERE website LIKE '%' || :query || '%' OR username LIKE '%' || :query || '%' OR title LIKE '%' || :query || '%'")
    LiveData<List<PasswordRepository>> searchPasswords(String query);
}